/**
 * @file wa_tick.c
 * 
 */

/*********************
 *      INCLUDES
 *********************/
#include "wa_tick.h"
/*********************
 *      DEFINES
 *********************/

/**********************
 *      TYPEDEFS
 **********************/

/**********************
 *  STATIC PROTOTYPES
 **********************/

/**********************
 *  STATIC VARIABLES
 **********************/

static uint32_t sys_time = 0;

/**********************
 *      MACROS
 **********************/

/**********************
 *   GLOBAL FUNCTIONS
 **********************/


/**
 * system tick inc
 * @param time
 */
void wa_tick_inc(uint32_t time)
{
	sys_time +=time;
}

/**
 * get system tick
 * @return
 */
uint32_t wa_tick_get(void)
{
	return sys_time;
}

/**
 * get relative time
 * @param prev_time 
 * @return
 */
uint32_t wa_tick_get_elap(uint32_t prev_time)
{
	uint32_t act_time;
	uint32_t elap_time;
	act_time=wa_tick_get();
	if(act_time>=prev_time)
	{
		elap_time=act_time-prev_time;
	}
	else
	{
		elap_time = UINT32_MAX - prev_time + 1;
		elap_time += act_time;
	}
	return elap_time;
}



/**********************
 *   STATIC FUNCTIONS
 **********************/
